package com.woniu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.CtfScore;
import com.woniu.entity.dto.CtfScoreDetailDTO;
import com.woniu.service.CtfScoreService;
import com.woniu.mapper.CtfScoreMapper;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
* @author nanqiao
* @description 针对表【ctf_score(得分表)】的数据库操作Service实现
* @createDate 2025-06-10 10:32:14
*/
@Service
public class CtfScoreServiceImpl extends ServiceImpl<CtfScoreMapper, CtfScore>
    implements CtfScoreService{

    //    根据考试ID查询得分记录
    @Override
    public List<CtfScoreDetailDTO> listByContestWithUserInfoAndContestInfo(Integer contestId) {
//        将三个对象存到集合中
        List<CtfScoreDetailDTO> list = baseMapper.listByContestWithUserInfoAndContestInfo(contestId);
        //根据CtfScoreDetailDTO中CtfScore中的totalScore进行排序
        list.sort(Comparator.comparingDouble((CtfScoreDetailDTO dto) ->
                        dto.getScore() != null ? dto.getScore().getTotalScore() : 0.0)
                .reversed());


        return list;
    }


}




